public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        Thread a = new Thread(()->{
           try{
               for (int i = 0; i < 5; i++) {
                   System.out.println("a正在运行");
                   Thread.sleep(1000);
               }
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
            System.out.println("a结束运行");
        }, "a");
        Thread b = new Thread(()->{
            try {
                a.join(3000);          // b线程只等a线程3秒, 3秒后b线程就不等了 ; 3秒=3000毫秒
                for (int i = 0; i < 5; i++) {
                    System.out.println("b正在运行");
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {
              e.printStackTrace();
            }

        }, "b");
         a.start();
         b.start();
    }
}
